#ifndef __LCD4P3_H
#define __LCD4P3_H

#ifdef APM32E10X_HD
	#include "apm32e10x_usart.h"
#elif defined AT32F403AVGT7
	#include "at32f403a_407_usart.h"		
#else
	#include "apm32f10x_usart.h"
#endif

#include "uart.h"
#include "tools.h"
#include <stdio.h>

#define       uart_DMA_send             uart1_DMA_send
#define       DISPLAY_BUFFER            uart1Ctrl.uartTxDatas
#if uart_DMA_send > 0
	#define       DISPLAY_DMA_Chn           UART1_DMA_Channel  
	#define       DISPLAY_DMA_flg_TC 				UART1_DMA_FLAG_TC  
#else
	#define       DISPLAY_USART             UART1_Id	
#endif

//指令帧头
#define       FRAME_HEADER_FIRST     0xA5
#define       FRAME_HEADER_SECOND    0x5A

//读写指令
#define       WRITE_REGISTER         0x80     //写寄存器
#define       READ_REGISTER          0x81     //读寄存器
#define       WRITE_VARIATE          0x82     //写变量
#define       READ_VARIATE           0x83     //读变量

//寄存器地址
#define       PIC_ID                 0x03      //读：当前显示页面ID;  写：切换到指定页面
#define       addr_beep              0x02      // 蜂鸣器地址
#define       addr_brightness        0x01      // 背光调整地址

//=====================================   各页面Id  ====================================//
#ifdef SQDri_EVSEB_7KW
	//等待插枪界面
	#define       PageId_WAIT_PLUG                                         0x0001 
	//等待充电界面
	#define       PageId_WAIT_CHG                                          0x0002 
	//正在充电界面
	#define       PageId_CHGING                                            0x0003
	//充电暂停页面[车触发停充]
	#define       PageId_CHARGE_SUSPEND                                    0x0004
	//充满停充页面[充满电并停充]
	#define       PageId_CHARGE_FULL                                       0x0005
	//刷卡页面
	#define       PageId_SWIPING_CARD                                      0x0006 
	//等待拔枪页面 
	#define       PageId_Wait_PLUGOUT                                      0x0007	
	//故障页-CP
	#define       PageId_ERROR_CP                                          0x0008
	//故障页-under_voltage
	#define       PageId_ERROR_under_voltage                               0x0009
	//故障页-over_voltage
	#define       PageId_ERROR_over_voltage                                0x000A
	//故障页-ungrounded
	#define       PageId_ERROR_ungrounded                                  0x000B
	//故障页-over_current
	#define       PageId_ERROR_over_current                                0x000C
	//故障页-short_circuit
	#define       PageId_ERROR_short_circuit                               0x000D
	//故障页-LEAKAGE
	#define       PageId_ERROR_LEAKAGE                                     0x000E
	//故障页-OVER_TEMPERATURE
	#define       PageId_ERROR_OVER_TEMPERATURE                            0x000F
	//故障页-EMERGENCY_STOP[急停按钮被按]
	#define       PageId_ERROR_EMERGENCY_STOP                              0x0010
	//故障页-RELAY_ADHESION
	#define       PageId_ERROR_RELAY_ADHESION                              0x0011
	//故障页-METERING_MODULE
	#define       PageId_ERROR_METERING_MODULE                             0x0012
	//故障页-NO_VENTILATION
	#define       PageId_ERROR_NO_VENTILATION                              0x0013
	//故障页-DIODE_FAULT
	#define       PageId_ERROR_DIODE_FAULT                                 0x0014
	//故障页-INPUT_POWER
	#define       PageId_ERROR_INPUT_POWER                                 0x0015	
	//故障详情页-CP
	#define       PageId_ERRDETAIL_CP                                      0x0016	
	//故障详情页-under_voltage
	#define       PageId_ERRDETAIL_under_voltage                           0x0017	
	//故障详情页-over_voltage
	#define       PageId_ERRDETAIL_over_voltage                            0x0018	
	//故障详情页-ungrounded
	#define       PageId_ERRDETAIL_ungrounded                              0x0019	
	//故障详情页-over_current
	#define       PageId_ERRDETAIL_over_current                            0x001A	
	//故障详情页-short_circuit
	#define       PageId_ERRDETAIL_short_circuit                           0x001B	
	//故障详情页-LEAKAGE
	#define       PageId_ERRDETAIL_LEAKAGE                                 0x001C	
	//故障详情页-OVER_TEMPERATURE
	#define       PageId_ERRDETAIL_OVER_TEMPERATURE                        0x001D	
	//故障详情页-EMERGENCY_STOP
	#define       PageId_ERRDETAIL_EMERGENCY_STOP                          0x001E	
	//故障详情页-RELAY_ADHESION
	#define       PageId_ERRDETAIL_RELAY_ADHESION                          0x001F	
	//故障详情页-METERING_MODU
	#define       PageId_ERRDETAIL_METERING_MODULE                         0x0020	
	//故障详情页-NO_VENTILATION
	#define       PageId_ERRDETAIL_NO_VENTILATION                          0x0021	
	//故障详情页-DIODE_FAULT
	#define       PageId_ERRDETAIL_DIODE_FAULT                             0x0022	
	//故障详情页-INPUT_POWER
	#define       PageId_ERRDETAIL_INPUT_POWER                             0x0023
	//安全检测界面
	#define       PageId_SECURITY_DETECTION                                0x0024  
	//自检界面
	#define       PageId_SELF_TEST                                         0x0025
	// 第一个故障页id
	#define       PageId_first_error_page                                  PageId_ERROR_CP
	// 第一个故障详情页id
	#define       PageId_first_error_detail                                PageId_ERRDETAIL_CP 

#elif defined SQDri_EVSEB_11KW
	//等待插枪界面
	#define       PageId_WAIT_PLUG                                         0x0001 
	//刷卡页面
	#define       PageId_SWIPING_CARD                                      0x0002
	//等待充电界面
	#define       PageId_WAIT_CHG                                          0x0003 
	//正在充电界面
	#define       PageId_CHGING                                            0x0004
	//充电暂停页面[车触发停充]
	#define       PageId_CHARGE_SUSPEND                                    0x0005
	//充满停充页面[充满电并停充]
	#define       PageId_CHARGE_FULL                                       0x0006
	//等待拔枪 
	#define       PageId_Wait_PLUGOUT                                      0x0007
	
	//故障页-CP
	#define       PageId_ERROR_CP                                          0x0008	
	//故障页-under_voltage
	#define       PageId_ERROR_under_voltage                               0x0009
	//故障页-over_voltage
	#define       PageId_ERROR_over_voltage                                0x000A
	//故障页-ungrounded
	#define       PageId_ERROR_ungrounded                                  0x000B
	//故障页-over_current
	#define       PageId_ERROR_over_current                                0x000C
	//故障页-short_circuit
	#define       PageId_ERROR_short_circuit                               0x000D
	//故障页-LEAKAGE
	#define       PageId_ERROR_LEAKAGE                                     0x000E
	//故障页-OVER_TEMPERATURE
	#define       PageId_ERROR_OVER_TEMPERATURE                            0x000F	
	//故障页-EMERGENCY_STOP
	#define       PageId_ERROR_EMERGENCY_STOP                              0x0010
		
	//故障详情页-CP
	#define       PageId_ERRDETAIL_CP                                      0x0011
	//故障详情页-under_voltage
	#define       PageId_ERRDETAIL_under_voltage                           0x0012
	//故障详情页-INPUT_POWER
	#define       PageId_ERRDETAIL_INPUT_POWER                             0x0013
	//故障详情页-ungrounded
	#define       PageId_ERRDETAIL_ungrounded                              0x0014
	//故障详情页-over_current
	#define       PageId_ERRDETAIL_over_current                            0x0015
	//故障详情页-short_circuit
	#define       PageId_ERRDETAIL_short_circuit                           0x0016
	//故障详情页-LEAKAGE
	#define       PageId_ERRDETAIL_LEAKAGE                                 0x0017	
	//故障详情页-OVER_TEMPERATURE
	#define       PageId_ERRDETAIL_OVER_TEMPERATURE                        0x0018	
	//故障详情页-EMERGENCY_STOP
	#define       PageId_ERRDETAIL_EMERGENCY_STOP                          0x0019	
	// 第一个故障页id
	#define       PageId_first_error_page                                  PageId_ERROR_CP
	// 第一个故障详情页id
	#define       PageId_first_error_detail                                PageId_ERRDETAIL_CP 
  
#endif
//=====================================  各变量地址 ====================================//
#if defined SQDri_EVSEB_7KW
	// 温度数据
	#define       DATA_TEMPEARTURE                                          0x0001   
	// 额定电流数据
	#define       DATA_RATED_CURRENT                                        0x000A
	// 实际电流数据 
	#define       DATA_PRACTICAL_CURRENT                                    0x0002
	// 充电电压数据
	#define       DATA_CHG_VOLTAGE                                          0x0005 
	// 电量数据
	#define       DATA_ELECTRIC_QUANTITY                                    0x0007
	// 时钟文本
	#define       TMRTXT_TIMER_SHOW                                         0x0100
	// 倒计时时钟文本
	#define       TMRTXT_COUNTDOWN                                          0x0013

#elif defined SQDri_EVSEB_11KW
  // 温度数据
	#define       DATA_TEMPEARTURE                                          0x0055   
	// 额定电流数据
	#define       DATA_RATED_CURRENT                                        0x000A
	// 实际电流数据L1 
	#define       DATA_PRACTICAL_CURRENT                                    0x0038
	// 实际电流数据L2
	#define       DATA2_PRACTICAL_CURRENT                                   0x003A
	// 实际电流数据L3
	#define       DATA3_PRACTICAL_CURRENT                                   0x003C	
	// 充电电压数据L1
	#define       DATA_CHG_VOLTAGE                                          0x002C
  // 充电电压数据L2
	#define       DATA2_CHG_VOLTAGE                                         0x002E
  // 充电电压数据L3
	#define       DATA3_CHG_VOLTAGE                                         0x0030	
	// 电量数据
	#define       DATA_ELECTRIC_QUANTITY                                    0x0050
	// 时钟文本
	#define       TMRTXT_TIMER_SHOW                                         0x0046
	// 倒计时时钟文本
	#define       TMRTXT_COUNTDOWN                                          0x0013
	// 充电桩编号
	#define       TXT_CHGR_ID                                               0x0001
	// 功率数据
	#define       DATA_CHGR_POWER                                           0x0070 
#endif


//================================= 函数声明 ========================================//
void display_write_register8(uint8_t addr,uint8_t value);
void display_write_register16(uint8_t addr,uint16_t value);
void display_write_variate(uint16_t addr,uint16_t value);
void display_write_arr_variate(uint16_t addr,int8_t *arrValue,uint8_t len);
void display_write_rtc(uint16_t addrRTC);
void change_page(uint16_t pageId);
uint8_t get_fault_idx(void);
void update_page(void);
void lcd_brightness_set(uint8_t brightnessValue);
#if beep_type == beep_LCD
void lcd_beep(uint8_t beepTm);
void beep_start(uint8_t beep_times_input,uint16_t beep_Tm_input,uint16_t beep_idle_Tm_input);
void lcd_beep_step_run(void);
#endif



#endif

